﻿using Coldairarrow.Business;
using Coldairarrow.Entity;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers
{
    [Route("/Order/[controller]/[action]")]
    public class Shop_CartController : BaseApiController
    {
        #region DI

        public Shop_CartController(IShop_CartBusiness shop_CartBus)
        {
            _shop_CartBus = shop_CartBus;
        }

        IShop_CartBusiness _shop_CartBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Shop_Cart>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _shop_CartBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Shop_Cart> GetTheData(IdInputDTO input)
        {
            return await _shop_CartBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Shop_Cart data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _shop_CartBus.AddDataAsync(data);
            }
            else
            {
                await _shop_CartBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _shop_CartBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}